package com.hxtec.polaris.controller;

import com.hxtec.polaris.entity.ShopAddress;
import com.hxtec.polaris.service.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Describtion 地址相关
 * @Author yonyong
 * @Date 2019/12/3 15:25
 * @Version 1.0.0
 **/
@RestController
@RequestMapping(value = "location",produces = "application/json;charset=utf-8")
@CrossOrigin
@Api(value = "/location", tags = "地址相关")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @GetMapping("get")
    public Object getLoaction(){
        return locationService.getLoaction();
    }

    @PostMapping("add")
    public Object addLoaction(ShopAddress shopAddress){
        return locationService.addLoaction(shopAddress);
    }

    @PutMapping("update")
    public Object updateLoaction(ShopAddress shopAddress){
        return locationService.updateLoaction(shopAddress);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids[]", value = "删除的地址集合",allowMultiple=true, dataType = "String")
    })
    @DeleteMapping("delete")
    public Object deleteLoaction(String ids){
        List<String> list = Arrays.asList(ids.split(","));
        return locationService.deleteLoaction(list);
    }

    @GetMapping("getDefault")
    public Object getDefaultLocation(){
        return locationService.getDefaultLocation();
    }

    @GetMapping("check")
    public Object checkLocation(ShopAddress shopAddress){
        return locationService.checkLocation(shopAddress);
    }
}
